<template>
<div class="login">
  <div style="width: 400px; margin: 150px auto">
    <div style="color: #cccccc; font-size: 30px; text-align: center; padding: 30px 0">欢迎登录</div>
    <el-form :model="form" ref="form" size="normal" >
      <el-form-item>
        <el-input :prefix-icon="User" v-model="form.username"/>
      </el-form-item>
      <el-form-item>
        <el-input :prefix-icon="Lock" v-model="form.password" show-password/>
      </el-form-item>
      <el-form-item>
        <el-button style="width: 100%" type="primary" @click="login">
          登录
        </el-button>
      </el-form-item>
    </el-form>
    <div class="text-center">
      <el-text class="mx-1" style="margin-left: 138px; color: white" @click="jump" >还没有账户？请点击注册</el-text>
    </div>
  </div>
</div>

</template>

<script>


import {Lock, User} from "@element-plus/icons-vue";
import request from "@/utils/request";

export default{
  name: "Login",
  //图标引用
  computed: {
    Lock() {
      return Lock
    },
    User() {
      return User
    }
  },
  data() {
    return {
      form: {}
    }
  },
  methods: {
    login(){
      request.post("/login", this.form).then(res =>
      {if(res.code === 200){
          this.$message({
            type: "success",
            message: "登陆成功"
          })
          this.$router.push("/home")
        }else{
          this.$message({
            type: "error",
            message: res.message
          })
        }
      })
    },
    jump(){
      this.$router.push("/sign_up")
    }
  }
}

</script>

<style scoped>
.login {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-image: url("../assets/static/1.png");
  position: fixed;
  background-size: 100% 100%;
}
</style>